import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:adaptive_action_sheet/adaptive_action_sheet.dart';

void main() {
  group('自适应操作表单测试', () {
    testWidgets('创建和显示基本操作表单', (WidgetTester tester) async {
      final actions = [
        BottomSheetAction(
          title: const Text('操作1'),
          onPressed: (context) => Navigator.of(context).pop(),
        ),
        BottomSheetAction(
          title: const Text('操作2'),
          onPressed: (context) => Navigator.of(context).pop(),
        ),
      ];

      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: Builder(
              builder: (context) => ElevatedButton(
                onPressed: () => showAdaptiveActionSheet(
                  context: context,
                  actions: actions,
                ),
                child: const Text('显示'),
              ),
            ),
          ),
        ),
      );

      await tester.tap(find.text('显示'));
      await tester.pumpAndSettle();

      expect(find.text('操作1'), findsOneWidget);
      expect(find.text('操作2'), findsOneWidget);
    });

    testWidgets('显示带取消按钮的操作表单', (WidgetTester tester) async {
      final actions = [
        BottomSheetAction(
          title: const Text('确认'),
          onPressed: (context) => Navigator.of(context).pop(),
        ),
      ];
      
      final cancelAction = CancelAction(title: const Text('取消'));

      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: Builder(
              builder: (context) => ElevatedButton(
                onPressed: () => showAdaptiveActionSheet(
                  context: context,
                  actions: actions,
                  cancelAction: cancelAction,
                ),
                child: const Text('显示'),
              ),
            ),
          ),
        ),
      );

      await tester.tap(find.text('显示'));
      await tester.pumpAndSettle();

      expect(find.text('确认'), findsOneWidget);
      expect(find.text('取消'), findsOneWidget);
    });

    testWidgets('测试操作点击关闭功能', (WidgetTester tester) async {
      final actions = [
        BottomSheetAction(
          title: const Text('删除'),
          onPressed: (context) => Navigator.of(context).pop(),
        ),
      ];

      await tester.pumpWidget(
        MaterialApp(
          home: Scaffold(
            body: Builder(
              builder: (context) => ElevatedButton(
                onPressed: () => showAdaptiveActionSheet(
                  context: context,
                  actions: actions,
                ),
                child: const Text('显示'),
              ),
            ),
          ),
        ),
      );

      await tester.tap(find.text('显示'));
      await tester.pumpAndSettle();
      
      expect(find.text('删除'), findsOneWidget);
      
      await tester.tap(find.text('删除'));
      await tester.pumpAndSettle();
      
      expect(find.text('删除'), findsNothing);
    });
  });
}